package goods

import (
	"errors"
	"fmt"
	"orm_gin/model"
	"orm_gin/orm"
	"orm_gin/utools/res"

	"github.com/gin-gonic/gin"
)

func DelGoods(c *gin.Context) {
	id := c.Query("id")

	userid, _ := c.Get("UserId")

	var goods model.UserGoods
	orm.DB.Where("user_info_id=?", userid).Find(&goods)

	fmt.Println("userid:", userid)
	if goods.UserInfoID != userid {
		res.Error(c, 0, errors.New("没有权限删除"), "没有权限删除")
		return
	}

	r := orm.DB.Where("id=?", id).Delete(&model.UserGoods{})
	if r.Error != nil {
		res.Error(c, 0, r.Error, error.Error(r.Error))
		return
	}

	res.Ok(c, nil, "操作成功")
}
